home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 2003 August / MW 8 2003 CD1.iso / Inside Macworld / Product News / gimp-1.2.4.sit / gimp-1.2.4 / plug-ins / perl / examples / roundrectsel < prev    next >
Encoding:
Text File  |  2000-05-21  |  2.1 KB  |  51 lines

  1. #!/usr/app/bin/perl
  2.  
  3. eval 'exec /usr/app/bin/perl  -S $0 ${1+"$@"}'
  4.     if 0; # not running under some shell
  5. # <sjburges@gimp.org>
  6. # This is adrian's idea - take random blends and difference them.  You're
  7. # bound to come up w/ something cool eventually.
  8.  
  9. use Gimp;
  10. use Gimp::Fu;
  11. use Gimp::Util;
  12.  
  13. # Gimp::set_trace(TRACE_ALL);
  14.  
  15. register "round_rect_sel", 
  16.          "Rounds a rectangular selection.",
  17.          "Rounds a rectangular selection. If no selection exists, it selects all first, then rounds that selection.  If there exists a selection, but its non-rectangluar, it will be replaced by a rectangluar one.",
  18.          "Seth Burgess", 
  19.          "Seth Burgess <sjburges\@gimp.org>", 
  20.          "1999-03-25",
  21.          N_"<Image>/Select/Round Rectangular Selection...", 
  22.          "*", 
  23.          [ 
  24.            [PF_SPINNER, "x_rounding", "How much to round in the horizontal, in pixels", 16, [1,1000,1]], 
  25.            [PF_SPINNER, "y_rounding", "How far to round the in vertical, in pixels", 16, [1,1000,1]], 
  26.             ], sub {
  27.     my($img,$layer,$x_round, $y_round) =@_;
  28.     eval { $img->undo_push_group_start };
  29.     @bounds = $img->selection_bounds;
  30.     # recreate the selection
  31.     $img->rect_select($bounds[1], $bounds[2], $bounds[3]-$bounds[1], $bounds[4]-$bounds[2], 0, 0, 0.5);
  32.  
  33.     # cut out the corners
  34.     $img->rect_select($bounds[1], $bounds[2], $x_round/2, $y_round/2, 1, 0, 0.5); 
  35.     $img->rect_select($bounds[3]-$x_round/2, $bounds[2], $x_round/2, $y_round/2, 1, 0, 0.5); 
  36.     $img->rect_select($bounds[3]-$x_round/2, $bounds[4]-$y_round/2, $x_round/2, $y_round/2, 1, 0, 0.5); 
  37.     $img->rect_select($bounds[1], $bounds[4]-$y_round/2, $x_round/2, $y_round/2, 1, 0, 0.5); 
  38.  
  39.     # add them back as elipses
  40.     
  41.     $img->ellipse_select($bounds[1], $bounds[2], $x_round, $y_round, 0, 1, 0, 0.5); 
  42.     $img->ellipse_select($bounds[3]-$x_round, $bounds[2], $x_round, $y_round, 0, 1, 0, 0.5); 
  43.     $img->ellipse_select($bounds[3]-$x_round, $bounds[4]-$y_round, $x_round, $y_round, 0, 1, 0, 0.5); 
  44.     $img->ellipse_select($bounds[1], $bounds[4]-$y_round, $x_round, $y_round, 0, 1, 0, 0.5); 
  45.  
  46.  
  47.     eval { $img->undo_push_group_end };
  48.     return();
  49. };
  50. exit main;
  51.